﻿using System.Linq;
using System.Collections.Generic;

namespace Watson.Msrc
{
    internal static class CVE_2019_0836
    {
        private const string name = "CVE-2019-0836";

        public static void Check(VulnerabilityCollection vulnerabilities, int buildNumber, List<int> installedKBs)
        {
            var supersedence = new List<int>();

            switch (buildNumber)
            {
                case 10240:

                    supersedence.AddRange(new int[] {
                        4493475, 4498375, 4499154, 4505051, 4503291,
                        4507458, 4512497, 4517276, 4522009, 4520011,
                        4524153, 4525232, 4530681, 4534306, 4537776,
                        4540693, 4550930, 4556826, 4561649, 4567518,
                        4565513, 4571692, 4577049
                    });

                    break;

                case 14393:

                    supersedence.AddRange(new int[] {
                        4493470, 4499418, 4494440, 4534271, 4534307,
                        4537764, 4537806, 4540670, 4541329, 4550929,
                        4550947, 4556813, 4561616, 4567517, 4565511,
                        4571694, 4577015
                    });

                    break;

                case 15063:

                    supersedence.AddRange(new int[] {
                        4493474, 4493436, 4499162, 4499181, 4502112,
                        4505055, 4503279, 4503289, 4509476, 4507450,
                        4507467, 4512474, 4512507, 4516059, 4516068,
                        4522011, 4520010, 4524151, 4525245, 4530711,
                        4534296, 4537765, 4540705, 4550939, 4556804,
                        4561605, 4567516, 4565499, 4571689, 4577021
                    });

                    break;

                case 16299:

                    supersedence.AddRange(new int[] {
                        4493441, 4493440, 4499147, 4499179, 4505062,
                        4503281, 4503284, 4509477, 4507455, 4507465,
                        4512494, 4512516, 4516066, 4522012, 4520004,
                        4520006, 4524150, 4525241, 4530714, 4534276,
                        4534318, 4537789, 4537816, 4540681, 4541330,
                        4554342, 4550927, 4556812, 4561602, 4567515,
                        4565508, 4571741, 4577041
                    });

                    break;

                case 17134:

                    supersedence.AddRange(new int[] {
                        4493464, 4493437, 4499167, 4499183, 4505064,
                        4503286, 4503288, 4509478, 4507435, 4507466,
                        4512501, 4512509, 4516045, 4516058, 4522014,
                        4519978, 4520008, 4524149, 4525237, 4530717,
                        4534293, 4534308, 4537762, 4537795, 4540689,
                        4541333, 4554349, 4550922, 4550944, 4556807,
                        4561621, 4567514, 4565489, 4571709, 4577032
                    });

                    break;

                case 17763:

                    supersedence.AddRange(new int[] {
                        4493509, 4495667, 4494441, 4497934, 4501835,
                        4505056, 4501371, 4503327, 4509479, 4505658,
                        4507469, 4511553, 4512534, 4512578, 4522015,
                        4519338, 4520062, 4524148, 4523205, 4530715,
                        4534273, 4534321, 4532691, 4537818, 4538461,
                        4541331, 4554354, 4549949, 4550969, 4551853,
                        4561608, 4567513, 4558998, 4559003, 4565349,
                        4571748, 4570333, 4577069
                    });

                    break;

                default:
                    return;
            }

            if (supersedence.Intersect(installedKBs).Any())
            {
                vulnerabilities.SetAsVulnerable(name);
            }
        }
    }
}